#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;



bool compare(int a1,int a2){
    string A = to_string(a1);
    string B = to_string(a2);
    int size = min(A.size(),B.size());
    for(int i = 0;i<size;++i){
        if(A[i]>B[i]){
            return true;
        }
        else if(A[i]<B[i]){
            return false;
        }
    }  
    return (A+B)>(B+A)? true:false;
}


class Solution {
public:
    string largestNumber(vector<int>& nums) {
        if(nums.size()==1){
            return to_string(nums[0]);
        }
        sort(nums.begin(),nums.end(),compare);
        if(nums[0]==0){
            return to_string(0);
        }
        string result = "";
        for(int i:nums){
            result += to_string(i);
        }
        return result;
    }
};

int main(){
    
    vector<int> nums = {3,30,34,5,9};
    Solution S;
    string A = S.largestNumber(nums);
    cout<<A<<endl;
    return 0;
}